package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusPipe;
import com.ruoyi.business.service.IBusPipeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 引入管台账Controller
 * 
 * @author wf
 * @date 2024-07-18
 */
@RestController
@RequestMapping("/business/pipe")
public class BusPipeController extends BaseController
{
    @Autowired
    private IBusPipeService busPipeService;
    @Value("${export.max:10000}")
    private Integer max;

    /**
     * 查询引入管台账列表
     */
    @PreAuthorize("@ss.hasPermi('business:pipe:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusPipe busPipe)
    {
        startPage();
        List<BusPipe> list = busPipeService.selectBusPipeList(busPipe);
        return getDataTable(list);
    }

    /**
     * 导出引入管台账列表
     */
    @PreAuthorize("@ss.hasPermi('business:pipe:export')")
    @Log(title = "引入管台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusPipe busPipe)
    {
        List<BusPipe> list = busPipeService.selectBusPipeList(busPipe);
        if (list.size() > max) {
            throw new ServiceException("导出失败！,每次最多导出 " + max + "条");
        }
        ExcelUtil<BusPipe> util = new ExcelUtil<BusPipe>(BusPipe.class);
        util.exportExcel(response, list, "引入管台账数据");
    }

    /**
     * 获取引入管台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:pipe:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busPipeService.selectBusPipeById(id));
    }

    /**
     * 新增引入管台账
     */
    @PreAuthorize("@ss.hasPermi('business:pipe:add')")
    @Log(title = "引入管台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusPipe busPipe)
    {
        return toAjax(busPipeService.insertBusPipe(busPipe));
    }

    /**
     * 修改引入管台账
     */
    @PreAuthorize("@ss.hasPermi('business:pipe:edit')")
    @Log(title = "引入管台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusPipe busPipe)
    {
        return toAjax(busPipeService.updateBusPipe(busPipe));
    }

    /**
     * 删除引入管台账
     */
    @PreAuthorize("@ss.hasPermi('business:pipe:remove')")
    @Log(title = "引入管台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busPipeService.deleteBusPipeByIds(ids));
    }
}
